<%--
  Created by IntelliJ IDEA.
  User: kangx
  Date: 2020/8/7
  Time: 23:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改员工</title>
    <link rel="stylesheet" href="${AppPath}/css/font.css">
    <link rel="stylesheet" href="${AppPath}/css/index.css">
    <script src="${AppPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${AppPath}/js/index.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" lay-fiter="empForm">
            <div class="layui-form-item">
                <label for="empName" class="layui-form-label">
                    <span class="x-red">*</span>姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="empName" name="empName" lay-fiter="empName" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>性别</label>
                <div class="layui-input-inline">
                    男 <input type="radio" name="studentSex" required="" value="男" checked="checked"  autocomplete="off" class="layui-input">
                    女 <input type="radio" name="studentSex" required="" value="女"  autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="empAge" class="layui-form-label">
                    <span class="x-red"></span>年龄
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="empAge" name="empAge"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="empPhone" class="layui-form-label">
                    <span class="x-red">*</span>电话
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="empPhone" name="empPhone" required="" lay-verify="phone"
                           autocomplete="off" class="layui-input">
                    <input type="hidden" name="empId" id="empId">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="deptId" class="layui-form-label">
                    <span class="x-red">*</span>院系
                </label>
                <div class="layui-input-inline">
                    <select name="deptId" lay-verify="required" lay-filter="deptId" id="deptId">
                        <option value="">请选择</option>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="deptId" class="layui-form-label">
                    <span class="x-red">*</span>照片
                </label>
                <div class="layui-input-inline" style="height:20px;padding-top: 9px ">
                    <input type="file" name="empImg" id="empImg" >
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button  class="layui-btn" lay-filter="update" lay-submit="">
                    增加
                </button>
            </div>
        </form>
    </div>
</div>
<script>


        //这样就把主窗体的值放到iframe层的隐藏控件了
        //你也可以直接拿到obj完成你的需求
        // alert(JSON.stringify(obj))
        layui.use('form',function(){
            var form = layui.form;
            layui.$.ajax({
                url:"${AppPath}/dept/findAll",
                type:"post",
                success:function(resp){
                    layui.$.each(resp,function (index,dept) {
                        var str='<option value="'+dept.deptId+'">'+dept.deptName+'</option>';
                        layui.$("#deptId").append(str)
                    })
                    form.render();
                }
            })
            // var str='<option value="男" >男</option>';
            // str+='<option value="女">女</option>'
            // layui.$("#empSex").append(str)
            // 监听提交按钮
            form.on('submit(update)', function(data){
                console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
                console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
                console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
                layui.$.ajax({
                    url:"${AppPath}/emp/add",
                    data:data.field,
                    type:"post",
                    success:function (resp) {
                        // var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        if (resp=='ok'){
                            layer.msg('添加成功！',{
                                icon: 1,
                                time: 1000 //2秒关闭（如果不配置，默认是3秒）
                            },function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg('请稍后再试！', {
                                icon: 2,
                                time: 1000 //2秒关闭（如果不配置，默认是3秒）
                            });
                        }
                    }
                })
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
        });


</script>
</body>
</html>
